<?php
/**
 * LICENSE
 * 
 * [license information]
 * 
 * @category   BKPay
 * @copyright  Copyright (c) 2011 bkpay.vn
 * @license    http://license.bkpay.vn
 * @version    v 1.0 2011-09-19
 * @author	   hoaihuong@9webdesigns.com, s50702790@gmail.com
 */
require_once 'Constant.php';

class BKPay_Function {
	
	/**
	 * Generator token for authentication transaction.
	 * @return string
	 */
	public static function generateToken() {
		return md5(time());
	}
	
	/**
	 * Generator activationCode for activate transaction
	 * @return string
	 */
	public static function generateActivationCode($length = 7)
	{
		$chars      = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
        $activeCode = '';
        for ($i = 1; $i <= $length; $i++) {
            $activeCode .= $chars{rand(0, 61)};
        }
        return $activeCode;
	}

	/**
	 * Convert object to array
	 * @param object class $obj
	 * @return array
	 */
	public static function objectToArray($obj) {
		$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
        foreach ($_arr as $key => $val) {
        	$val = (is_array($val) || is_object($val)) ? self::objectToArray($val) : $val;
            $arr[$key] = $val;
        }
        return $arr;
	}
	
}